<template>
<div>
    <table>
      <tr>
        <td>名称</td>
        <td>价格</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in list">
        <td>{{i.name}}</td>
        <td>{{i.price}}</td>
        <td><button @click="buy(i.id)">购买</button></td>
      </tr>
    </table>
</div>
</template>

<script>
export default {
  name: "flask_goods",
  data(){
    return{
      list:[],
      userid:localStorage.getItem('userid')
    }
  },
  methods:{
    get(){
      this.$axios.get('').then(res=>{
        this.list = res.data.list
      })
    },
    buy(id){
      if (this.userid){
          this.$axios.post('/cartM',{'userid':this.userid,'goodsid':id}).then(res=>{
            console.log(res.data)
          })
      }else {
        this.$router.push('flask_login')
      }
    }
  },
  mounted() {
    this.get()
  }
}
</script>

<style scoped>

</style>
